<include file="Public/head" />

<body class="no-skin">
    <include file="Public/header" />
    <div class="main-container" id="main-container">
        <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {}
        </script>
        <include file="Public/sidebar" />
        <div class="main-content">
            <div class="main-content-inner">
                <!-- #section:basics/content.breadcrumbs -->
                <include file="Public/breadcrumbs" />
                <!-- /section:basics/content.breadcrumbs -->
                <div class="page-content">
                    <include file="Public/set" />
                    <!-- /section:settings.box -->
                    <div class="row">
                        <div class="col-xs-12">
                            <!-- PAGE CONTENT BEGINS -->
                            <div class="row">
                                <form class="form-inline" action="" method="get">
                                    <a class="btn btn-info btn-sm" href="{:U('add')}" value="">新增</a>
                                    <label class="inline">用户搜索</label>
                                    <select name="field" class="form-control">
                                        <option <if condition="I('field') eq user">selected</if> value="user">用户名</option>
                                        <option <if condition="I('field') eq phone">selected</if> value="phone">电话</option>
                                        <option <if condition="I('field') eq qq">selected</if> value="qq">QQ</option>
                                        <option <if condition="I('field') eq email">selected</if> value="email">邮箱</option>
                                    </select>
                                    <input type="text" name="keyword" value="{:I(keyword)}" class="form-control">
                                    <label class="inline">&nbsp;&nbsp;排序：</label>
                                    <select name="order" class="form-control">
                                        <option <if condition="I('order') eq asc">selected</if> value="asc">注册时间升</option>
                                        <option <if condition="I('order') eq desc">selected</if> value="desc">注册时间降</option>
                                    </select>
                                    <button type="submit" class="btn btn-purple btn-sm">
                                        <span class="ace-icon fa fa-search icon-on-right bigger-110"></span> Search
                                    </button>
                                </form>
                            </div>
                            <div class="space-4"></div>
                            <div class="row">
                                <form id="form" method="post" action="{:U('del')}">
                                    <table class="table table-striped table-bordered table-hover">
                                        <thead>
                                            <tr>
                                                <th class="center">
                                                    <label class="pos-rel">
                                                        <input class="ace check-all" type="checkbox" value=""> <span class="lbl"></span>
                                                    </label>
                                                </th>
                                                <th>用户名</th>
                                                <th>用户组</th>
                                                <th class="center">性别</th>
                                                <th class="center">生日</th>
                                                <th>电话</th>
                                                <th>Q&nbsp;Q</th>
                                                <th>邮箱</th>
                                                <th class="center">操作</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <style>
                                            .grouptd {
                                                position: relative;
                                            }

                                            .group {
                                                display: inline-block;
                                                width: 100%;
                                            }

                                            .groupselect {
                                                position: absolute;
                                                top: 0;
                                                left: 0;
                                                width: 100%;
                                                height: 100%;
                                                border: 0;
                                            }
                                            </style>
                                            <volist name="list" id="val">
                                                <tr>
                                                    <td class="center">
                                                        <if condition="$val['uid'] neq 1">
                                                            <!-- <input class="uids" type="checkbox" name="uids[]" value="{$val['uid']}"> -->
                                                            <label class="pos-rel">
                                                                <input class="ace uids" name="uids[]" type="checkbox" value="{$val['uid']}"> <span class="lbl"></span>
                                                            </label>
                                                            <else/>
                                                            <span title="系统管理员，禁止删除">--</span></if>
                                                    </td>
                                                    <td>{$val['user']}</td>
                                                    <td class="grouptd">
                                                        <span class="group" val="{$val['uid']}">{$val['title']}</span>
                                                        <select class="groupselect hide">
                                                            <volist name="group" id="v">
                                                                <option <if condition="$val['gid'] eq $v['id']">selected="selected"</if>
                                                                    value="{$v.id}">{$v.title}</option>
                                                            </volist>
                                                        </select>
                                                    </td>
                                                    <td class="center">
                                                        <?php if($val['sex']==1){echo '男';}elseif($val['sex']==2){echo '女';}else{echo '保密';} ?>
                                                    </td>
                                                    <td class="center">{$val['birthday']|date="Y-m-d",###}</td>
                                                    <td>{$val['phone']}</td>
                                                    <td>{$val['qq']}</td>
                                                    <td>{$val['email']}</td>
                                                    <td class="center"><a href="{:U('edit',array('uid'=>$val['uid']))}">修改</a>&nbsp;
                                                        <if condition="$val['uid'] neq 1"><a class="del" href="javascript:;" val="{:U('del',array('uid'=>$val['uid']))}" title="删除">删除</a></if>
                                                    </td>
                                                </tr>
                                            </volist>
                                        </tbody>
                                    </table>
                                </form>
                                <div class="cf">
                                    <input id="submit" class="btn btn-danger btn-sm" type="button" value="删除">
                                </div>
                                {$page}
                            </div>
                            <!-- PAGE CONTENT ENDS -->
                        </div>
                        <!-- /.col -->
                    </div>
                    <!-- /.row -->
                </div>
                <!-- /.page-content -->
            </div>
        </div>
        <!-- /.main-content -->
        <include file="Public/footer" />
    </div>
    <!-- /.main-container -->
    <include file="Public/footerjs" />
    <!-- inline scripts related to this page -->
    <script type="text/javascript">
    $(function() {
        $(".group").click(function() {
            $(this).addClass('hide');
            $(this).parent().find(".groupselect").removeClass('hide');
        })
        $(".groupselect").on("change", function() {
            var ob = $(this);
            var gid = ob.val();
            var uid = ob.parent().find('.group').attr('val');
            $.get("{:U('update')}?ajax=yes&uid=" + uid + "&gid=" + gid, function(data) {
                var text = ob.find("option:selected").text();
                ob.parent().find(".group").removeClass('hide').html(text);
                ob.addClass('hide');
            });
        })

        $(".check-all").click(function() {
            $(".uids").prop("checked", this.checked);
        });
        $(".uids").click(function() {
            var option = $(".ids");
            option.each(function(i) {
                if (!this.checked) {
                    $(".check-all").prop("checked", false);
                    return false;
                } else {
                    $(".check-all").prop("checked", true);
                }
            });
        });
        $("#submit").click(function() {
            bootbox.confirm({
                title: "系统提示",
                message: "是否要删除所选用户？",
                callback: function(result) {
                    if (result) {
                        $("#form").submit();
                    }
                },
                buttons: {
                    "cancel": { "label": "取消" },
                    "confirm": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
        });
        $(".del").click(function() {
            var url = $(this).attr('val');
            bootbox.confirm({
                title: "系统提示",
                message: "是否要删除该用户?",
                callback: function(result) {
                    if (result) {
                        window.location.href = url;
                    }
                },
                buttons: {
                    "cancel": { "label": "取消" },
                    "confirm": {
                        "label": "确定",
                        "className": "btn-danger"
                    }
                }
            });
        });
    })
    </script>
</body>

</html>